package mythesis.controller;
/*
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.io.File;
 */

import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.io.*;

public class XMLJavaParser2
{
	public static void main(String args[])
	{
		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

		try
		{
			DocumentBuilder db = dbf.newDocumentBuilder();
			Document doc = db.parse(new FileInputStream("C:/Users/ncinco/Eclipse/workspace/ClueMeRemake/src/mythesis/test/SampleAI.xml"));
			
			Element root = doc.getDocumentElement();
			System.out.println("Root name: " + root.getNodeName());
			
			NodeList events = root.getElementsByTagName("event");
			System.out.println("Number of events : " + events.getLength() + "\n\n");

			for (int i=0; i<events.getLength(); i++)
			{
				// get employee element
				Element el = (Element)events.item(i);
				String type = el.getAttribute("type");
				System.out.println("EVENT: " + type + "\n-----------");
				
				// get asdf children
				//NodeList nl = el.getElementsByTagName("asdf");
				//System.out.println(" > " + nl.item(0).getTextContent());
				
				// get all tiles
				NodeList tiles = el.getElementsByTagName("tile");
				System.out.println(" # of tiles : " + tiles.getLength());
				
				// loop through all tiles
				for (int j=0; j<tiles.getLength(); j++)
				{
					Element ti = (Element)tiles.item(j);
					
					// get name and line
					String tileType   = ti.getAttribute("type");
					String lineNumber = ti.getAttribute("line");
					System.out.print(" > " + lineNumber + " : " + tileType);
					//int a = Integer.parseInt(s)
					
					// get all arguments
					NodeList argList = el.getElementsByTagName("arg");
					
					
					for (int k=0; k<argList.getLength(); k++)
					{
						Element arg    = (Element)argList.item(k);
						String argText = arg.getTextContent();
						System.out.print(" ("+argText+")");
					}
					System.out.println("");
				}
				
				System.out.println("");
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
}
